package com.lagou.edu.course.controller;

import com.lagou.edu.course.api.dto.SectionDTO;
import com.lagou.edu.course.remote.SectionService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 课程章节Controller
 *
 * @author lm
 * @since 2021/10/29 16:11
 */
@Slf4j
@RestController
@RequestMapping("/course/section")
public class SectionController {
    @Autowired
    SectionService sectionService;

    /**
     * 通过课程Id获取章节和课时
     * @param courseId
     * @return
     */
    @GetMapping(value = "/getSectionAndLesson")
    public List<SectionDTO> getSectionAndLesson(@RequestParam("courseId") Integer courseId){
        log.info("通过课程Id获取章节和课时 courseId:{}",courseId);
        return sectionService.getSectionAndLesson(courseId);
    }

    /**
     * 保存课程章节
     *
     * @param sectionDTO 章节内容
     * @return
     */
    @PostMapping("/saveOrUpdateSection")
    boolean saveOrUpdateSection(@RequestBody SectionDTO sectionDTO) {
        return sectionService.saveOrUpdateSection(sectionDTO);
    }
}
